package org.homly.admin.action.product;

import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.homly.sql.SQLTool;

/**
 * 获取品牌列表
 * @author Dragon
 * @date 2012-11-14
 *
 */
public class GetProductBrandAction extends Action {
	
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		String sql = " select distinct product_brand_name from product where product_status=1 ";
		String typeId = request.getParameter("typeId");
		if(typeId != null && typeId.matches("\\d+")) {
			sql += " and config_id=" + typeId;
		}
		sql +=" order by product_brand_name ";
		List<HashMap<String, String>> list = SQLTool.query(sql);
		JSONArray jsonArray = JSONArray.fromObject(list);
		response.getWriter().print(jsonArray);
		return null;
	}

}
